package com.fira.edu.service.impl;

import java.util.List;
import com.fira.common.utils.DateUtils;
import com.fira.common.utils.uuid.IdUtils;
import com.fira.edu.domain.EduCourse;
import com.fira.edu.mapper.EduCourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fira.edu.mapper.EduCourseMealMapper;
import com.fira.edu.domain.EduCourseMeal;
import com.fira.edu.service.IEduCourseMealService;
import com.fira.common.core.text.Convert;

/**
 * 课程套餐Service业务层处理
 * 
 * @author zhushuyong
 * @date 2021-10-01
 */
@Service
public class EduCourseMealServiceImpl implements IEduCourseMealService 
{
    @Autowired
    private EduCourseMealMapper eduCourseMealMapper;
    @Autowired
    private EduCourseMapper eduCourseMapper;

    /**
     * 查询课程套餐
     * 
     * @param id 课程套餐ID
     * @return 课程套餐
     */
    @Override
    public EduCourseMeal selectEduCourseMealById(String id)
    {
        return eduCourseMealMapper.selectEduCourseMealById(id);
    }

    /**
     * 查询课程套餐列表
     * 
     * @param eduCourseMeal 课程套餐
     * @return 课程套餐
     */
    @Override
    public List<EduCourseMeal> selectEduCourseMealList(EduCourseMeal eduCourseMeal)
    {
        List<EduCourseMeal> courseMealList = eduCourseMealMapper.selectEduCourseMealList(eduCourseMeal);
        courseMealList.forEach(item -> {
            EduCourse course = eduCourseMapper.selectEduCourseById(item.getCourseId());
            item.setCourseId(course.getCourseName() + "-" + course.getCourseType());
        });
        return courseMealList;
    }

    /**
     * 新增课程套餐
     * 
     * @param eduCourseMeal 课程套餐
     * @return 结果
     */
    @Override
    public int insertEduCourseMeal(EduCourseMeal eduCourseMeal)
    {
        eduCourseMeal.setId(IdUtils.fastSimpleUUID());
        eduCourseMeal.setCreateTime(DateUtils.getNowDate());
        return eduCourseMealMapper.insertEduCourseMeal(eduCourseMeal);
    }

    /**
     * 修改课程套餐
     * 
     * @param eduCourseMeal 课程套餐
     * @return 结果
     */
    @Override
    public int updateEduCourseMeal(EduCourseMeal eduCourseMeal)
    {
        eduCourseMeal.setUpdateTime(DateUtils.getNowDate());
        return eduCourseMealMapper.updateEduCourseMeal(eduCourseMeal);
    }

    /**
     * 删除课程套餐对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteEduCourseMealByIds(String ids)
    {
        return eduCourseMealMapper.deleteEduCourseMealByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除课程套餐信息
     * 
     * @param id 课程套餐ID
     * @return 结果
     */
    @Override
    public int deleteEduCourseMealById(String id)
    {
        return eduCourseMealMapper.deleteEduCourseMealById(id);
    }
}
